package com.welove.fragments;

import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.welove.R;
import com.welove.app.TBaseApplication;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class LoadFragment extends Fragment{

	private LocationClient mLocClient;
	private TBaseApplication tApp;
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
	}

	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		/*
		 * 开始定位操作
		 */
		tApp=(TBaseApplication)getActivity().getApplication();
		mLocClient = tApp.mLocationClient;
		
		setLocationOption();
		mLocClient.requestLocation();	
		mLocClient.start();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view=inflater.inflate(R.layout.fragment_load,container,false);
		return view;
	}

	private void setLocationOption(){
		LocationClientOption option = new LocationClientOption();
		option.setOpenGps(false);			
		option.setCoorType("gcj02");	
		option.setServiceName("com.baidu.location.service_v2.9");
		option.setAddrType("all");
			
		
		option.setScanSpan(5000);
		
		option.setPriority(LocationClientOption.NetWorkFirst);  
		mLocClient.setLocOption(option);
		
		option.disableCache(true);		
		mLocClient.setLocOption(option);
	}
	
	
}
